package jp.sourceforge.akjrcp.flvtools.basic;

import jp.sourceforge.akjrcp.akj_betas.Messages;
import jp.sourceforge.akjrcp.ffmpeg.FFMpegUI;

import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.FileFieldEditor;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.program.Program;
import org.eclipse.swt.widgets.Link;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;


/**
 * This class represents a preference page that
 * is contributed to the Preferences dialog. By 
 * subclassing <samp>FieldEditorPreferencePage</samp>, we
 * can use the field support built into JFace that allows
 * us to create a page that is small and knows how to 
 * save, restore and apply itself.
 * <p>
 * This page is used to modify preferences only. They
 * are stored in the preference store that belongs to
 * the main plug-in class. That way, preferences can
 * be accessed directly via the preference store.
 */


public class FFMpegPage
	extends FieldEditorPreferencePage
	implements IWorkbenchPreferencePage {


	
	public FFMpegPage() {
		super(GRID);
		//setPreferenceStore(Akj_betasPlugin.getDefault().getPreferenceStore());
		setPreferenceStore(PlatformUI.getPreferenceStore());//public
		setDescription(Messages.getString("ffmpeg_description")); //$NON-NLS-1$
		initializeDefaults();
	}
/**
 * Sets the default values of the preferences.
 */
	private void initializeDefaults() {
		
	}
	
/**
 * Creates the field editors. Field editors are abstractions of
 * the common GUI blocks needed to manipulate various types
 * of preferences. Each field editor knows how to save and
 * restore itself.
 */

	

    protected void createFieldEditors() {
    
        FileFieldEditor fileField=new FileFieldEditor(
                FFMpegUI.FFMPEG_PATH, Messages.getString("ffmpeg_path"),getFieldEditorParent()); //$NON-NLS-1$
        fileField.setFileExtensions(new String[]{"ffmpeg.exe"}); //$NON-NLS-1$
        addField(fileField);
        
        //description of ffmpeg.exe
        Link link = new Link(getFieldEditorParent(), SWT.NONE);
        link.setText(Messages.getString("ffmpeg.how_to_setup"));
        link.addSelectionListener(new org.eclipse.swt.events.SelectionAdapter() {
            public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            	Program p=Program.findProgram("html");
        		
        		p.execute("http://www.xucker.jpn.org/pc/ffmpegnew.html");
        	
            }
        });
        
        GridData data=new GridData();
        data.horizontalSpan=3;//magic number
        link.setLayoutData(data);
       
        
        
        FileFieldEditor fileField2=new FileFieldEditor(
        		FFMpegUI.PURE_FFMPEG_PATH, Messages.getString("pure_ffmpeg_path"),getFieldEditorParent()); //$NON-NLS-1$
        fileField2.setFileExtensions(new String[]{"pure_ffmpeg.exe;ffmpeg.exe"}); //$NON-NLS-1$
        addField(fileField2);
        
        BooleanFieldEditor primary=new BooleanFieldEditor(FFMpegUI.USE_PURE_FFMPEG, Messages.getString("use_pure_ffmpeg"),getFieldEditorParent());
        addField(primary);
        

        addField(new BooleanFieldEditor(FFMpegUI.USE_THREAD,Messages.getString(FFMpegUI.USE_THREAD),getFieldEditorParent())); //$NON-NLS-1$
        
        addField(new BooleanFieldEditor(FFMpegUI.DEMUX_SOME_VIDEO,Messages.getString(FFMpegUI.DEMUX_SOME_VIDEO),getFieldEditorParent())); //$NON-NLS-1$
        
        addField(new BooleanFieldEditor(FFMpegUI.ALERT_PTHREAD,Messages.getString(FFMpegUI.ALERT_PTHREAD),getFieldEditorParent())); //$NON-NLS-1$
        
        //addField(new IntegerFieldEditor(AC3_DEFAULT_BITRATE,"ac3 default bitrate",getFieldEditorParent()));
    }
	
	public void init(IWorkbench workbench) {
		IPreferenceStore store = getPreferenceStore();
		
	}
}